/*
https://leetcode.cn/problems/daily-temperatures/submissions/581511619/
*/
class Solution {
public:
    vector<int> dailyTemperatures(vector<int>& nums) {
        int n = nums.size();
        vector<int> result(n);
        stack<int> st;
        for (int i =n - 1; i >=0  ; --i) {
            int t=nums[i];
            while (!st.empty() && t >= nums[st.top()]) {
                st.pop();
            }
            if(!st.empty()){
                result[i]=st.top()-i;
            }
            st.push(i);
        }

        return result;
    }

};